home *** CD-ROM | disk | FTP | other *** search
- Path: news.deltanet.com!usenet
- From: kkhan@deltanet.com (AK)
- Newsgroups: comp.lang.c++
- Subject: Help a newbie with a problem....
- Date: Sun, 04 Feb 1996 21:44:32 GMT
- Organization: Delta Internet Services, Anaheim, CA
- Message-ID: <311527bc.180318@news.deltanet.com>
- NNTP-Posting-Host: rvr0145.deltanet.com
- X-Newsreader: Forte Agent .99c/16.141
-
- Ok I have no clue as to what is wrong with this statement, I have
- tried various forms with no success. The statement is supposed to give
- me a factorial result with this formula : (n - r + 1) / r.
-
- Here is my code:
- int num, // Number of balls in the bin.
- sel, // Number of balls selected.
- fact; // Sets the factorial
- long combo; // The odds of winning lottery.
-
- // Prompt for user to enter the number of balls total and number
- // selected.
- cout << endl << "Enter the number of balls in bin: ";
- cin >> num;
- cout << endl << "Enter the number of balls selected: ";
- cin >> sel;
-
- // A loop used to calculate the odds with the values given by the
- user.
- for ( int r = 1; r <= sel; r++)
- {
- combo = 1;
- for ( int fact = ( (num - r + 1) / r ); fact <= r; fact++)
- { combo *= fact; }
-
- }
- cout << endl << "Odds of winning: 1 in " << combo;
- }
-
- Any help will be greatly appreciated.
-